package com.tuyrt.windy.ui.weather

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import com.tuyrt.windy.logic.Repository
import com.tuyrt.windy.logic.model.Location

/**
 * Created by tuyrt7 on 2021/4/14.
 */
class WeatherViewModel : ViewModel() {

    private val locationLiveData = MutableLiveData<Location>()

    val weatherLiveData = Transformations.switchMap(locationLiveData) { location ->
        Repository.refreshWeather(location.lat, location.lng)
    }

    fun refreshWeather(lat: String, lng: String) {
        Log.d("aaaa", "lat: $lat , lng: $lng")
        locationLiveData.value = Location(lat, lng)
    }

    /**
     *  viewModel 存储和页面有关的数据
     */

    var locationLat = ""
    var locationLng = ""
    var placeName = ""

}